# Methods added to this helper will be available to all templates in the application.

module ApplicationHelper
  def bbcode2html(text)
    text.gsub!(/\[code\]/i, "[code=ruby]")
    text.scan(/(\[code\=([a-z].+?)\](.+?)\[\/code\])/m).each do |match|
      text.gsub!(match[0],CodeRay.scan(match[2].strip, match[1].to_sym).div( :line_numbers => :table, :css => :class))
    end
    text = BBCodeizer.bbcodeize(text)
    text.gsub!(/\r\n/i, "<br/>")
    return "<br/>" + text
  end
  
  def error_messages(m)
    messages = []
    m.errors.each do |attr, msg|
      messages << msg
    end
    return messages.join("<br/>")
  end
end
